package org.wu.acw.server.infrastructure.persistence;

import org.wu.acw.server.infrastructure.entity.AcwSingleTableOperationLogDO;
import org.wu.acw.server.infrastructure.converter.AcwSingleTableOperationLogConverter;
import org.wu.acw.server.domain.model.acw.single.table.operation.log.AcwSingleTableOperationLogRepository;
import org.springframework.stereotype.Repository;
import java.util.stream.Collectors;
import org.wu.framework.lazy.orm.database.lambda.stream.wrapper.LazyWrappers;
import org.wu.framework.web.response.Result;
import org.wu.framework.web.response.ResultFactory;
import jakarta.annotation.Resource;
import org.wu.acw.server.domain.model.acw.single.table.operation.log.AcwSingleTableOperationLog;
import org.wu.framework.lazy.orm.database.lambda.stream.lambda.LazyLambdaStream;
import java.util.List;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
/**
 * describe 单表操作日志 
 *
 * @author Jia wei Wu
 * @date 2024/04/29 09:55 上午
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyInfrastructurePersistence 
 **/
@Repository
public class AcwSingleTableOperationLogRepositoryImpl  implements  AcwSingleTableOperationLogRepository {

    @Resource
    LazyLambdaStream lazyLambdaStream;

    /**
     * describe 新增单表操作日志
     *
     * @param acwSingleTableOperationLog 新增单表操作日志     
     * @return {@link Result<AcwSingleTableOperationLog>} 单表操作日志新增后领域对象     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<AcwSingleTableOperationLog> story(AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        lazyLambdaStream.upsert(acwSingleTableOperationLogDO);
        return ResultFactory.successOf();
    }

    /**
     * describe 批量新增单表操作日志
     *
     * @param acwSingleTableOperationLogList 批量新增单表操作日志     
     * @return {@link Result<List<AcwSingleTableOperationLog>>} 单表操作日志新增后领域对象集合     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<List<AcwSingleTableOperationLog>> batchStory(List<AcwSingleTableOperationLog> acwSingleTableOperationLogList) {
        List<AcwSingleTableOperationLogDO> acwSingleTableOperationLogDOList = acwSingleTableOperationLogList.stream().map(AcwSingleTableOperationLogConverter.INSTANCE::fromAcwSingleTableOperationLog).collect(Collectors.toList());
        lazyLambdaStream.upsert(acwSingleTableOperationLogDOList);
        return ResultFactory.successOf();
    }

    /**
     * describe 查询单个单表操作日志
     *
     * @param acwSingleTableOperationLog 查询单个单表操作日志     
     * @return {@link Result<AcwSingleTableOperationLog>} 单表操作日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<AcwSingleTableOperationLog> findOne(AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        AcwSingleTableOperationLog acwSingleTableOperationLogOne = lazyLambdaStream.selectOne(LazyWrappers.lambdaWrapperBean(acwSingleTableOperationLogDO), AcwSingleTableOperationLog.class);
        return ResultFactory.successOf(acwSingleTableOperationLogOne);
    }

    /**
     * describe 查询多个单表操作日志
     *
     * @param acwSingleTableOperationLog 查询多个单表操作日志     
     * @return {@link Result<List<AcwSingleTableOperationLog>>} 单表操作日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<List<AcwSingleTableOperationLog>> findList(AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        List<AcwSingleTableOperationLog> acwSingleTableOperationLogList = lazyLambdaStream.selectList(LazyWrappers.lambdaWrapperBean(acwSingleTableOperationLogDO), AcwSingleTableOperationLog.class);
        return ResultFactory.successOf(acwSingleTableOperationLogList);
    }

    /**
     * describe 分页查询多个单表操作日志
     *
     * @param size 当前页数
     * @param current 当前页
     * @param acwSingleTableOperationLog 分页查询多个单表操作日志     
     * @return {@link Result<LazyPage<AcwSingleTableOperationLog>>} 分页单表操作日志领域对象     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<LazyPage<AcwSingleTableOperationLog>> findPage(int size,int current,AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        LazyPage<AcwSingleTableOperationLog> lazyPage = new LazyPage<>(current,size);
        LazyPage<AcwSingleTableOperationLog> acwSingleTableOperationLogLazyPage = lazyLambdaStream.selectPage(LazyWrappers.lambdaWrapperBean(acwSingleTableOperationLogDO),lazyPage, AcwSingleTableOperationLog.class);
        return ResultFactory.successOf(acwSingleTableOperationLogLazyPage);
    }

    /**
     * describe 删除单表操作日志
     *
     * @param acwSingleTableOperationLog 删除单表操作日志     
     * @return {@link Result<AcwSingleTableOperationLog>} 单表操作日志     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<AcwSingleTableOperationLog> remove(AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        //  lazyLambdaStream.delete(LazyWrappers.lambdaWrapperBean(acwSingleTableOperationLogDO));
        return ResultFactory.successOf();
    }

    /**
     * describe 是否存在单表操作日志
     *
     * @param acwSingleTableOperationLog 单表操作日志领域对象     
     * @return {@link Result<Boolean>} 是否存在 true 存在，false 不存在     
     
     * @author Jia wei Wu
     * @date 2024/04/29 09:55 上午
     **/

    @Override
    public Result<Boolean> exists(AcwSingleTableOperationLog acwSingleTableOperationLog) {
        AcwSingleTableOperationLogDO acwSingleTableOperationLogDO = AcwSingleTableOperationLogConverter.INSTANCE.fromAcwSingleTableOperationLog(acwSingleTableOperationLog);
        Boolean exists=lazyLambdaStream.exists(LazyWrappers.lambdaWrapperBean(acwSingleTableOperationLogDO));
        return ResultFactory.successOf(exists);
    }

}